//
//  SXTMyHeadView.m
//  SXT
//
//  Created by 赵金鹏 on 16/8/17.
//  Copyright © 2016年 赵金鹏. All rights reserved.
//

#import "SXTMyHeadView.h"
#import <Masonry.h>
@interface SXTMyHeadView()

@property (strong, nonatomic)   UIImageView *backImageView;              /** 背景图片 */
@property (strong, nonatomic)   UIButton *landingBtn;              /** 注册button */
@property (strong, nonatomic)   UIButton *loginBtn;              /** 登录button */
@end

@implementation SXTMyHeadView
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.backImageView ];
        [self addSubview:self.loginBtn];
        [self addSubview:self.landingBtn];
    }
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    __weak typeof (self) weakSelf = self;
    [_backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(weakSelf).with.insets(UIEdgeInsetsMake(0, 0, 0, 0));
    }];
    
    [_landingBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(weakSelf.mas_centerX).offset(60);
        make.centerY.equalTo(weakSelf.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(45, 23));
    }];
    
    [_loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(weakSelf.mas_centerX).offset(-60);
        make.centerY.equalTo(weakSelf.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(45, 23));
    }];
}

- (UIImageView *)backImageView{
    if (!_backImageView) {
        _backImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"我的背景"]];
    }
    return _backImageView;
}

- (UIButton *)landingBtn{
    if (!_landingBtn) {
        _landingBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [_landingBtn setTitle:@"注册" forState:(UIControlStateNormal)];
        [_landingBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
        [_landingBtn addTarget:self action:@selector(pushLandingViewController) forControlEvents:(UIControlEventTouchUpInside)];
        _landingBtn.backgroundColor = [UIColor clearColor];
    }
    return _landingBtn;
}

- (UIButton *)loginBtn{
    if (!_loginBtn) {
        _loginBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [_loginBtn setTitle:@"登录" forState:(UIControlStateNormal)];
        [_loginBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
        _loginBtn.backgroundColor = [UIColor clearColor];
    }
    return _loginBtn;
}

- (void)pushLandingViewController{
    if (_landingBlock) {
        _landingBlock();
    }
}
@end
